package com.example.ccjml;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.example.ccj.b.a.BaseActivity;
import com.example.ccj.b.c.dialog.LoadingDialog;
import com.example.ccj.b.c.form.CreateFormDialog;
import com.example.ccj.b.c.form.FormDataFormatter;
import com.example.ccj.b.c.form.InPutData;
import com.example.ccj.b.c.form.LoadFormDataView;
import com.example.ccj.b.c.form.OptionFormatter;
import com.example.ccj.b.c.form.ShowDataFieldView;
import com.example.ccj.u.LogUtils;
import com.example.ccj.u.ToastUtils;

import java.util.ArrayList;
import java.util.List;

public class TestCreateFormActivity extends BaseActivity {


    @Override
    public void initData(@Nullable Bundle bundle) {

    }

    @Override
    public void initView(@Nullable Bundle savedInstanceState, @Nullable View contentView) {
        Button open = findViewById(R.id.activity_test_create_form_open);
        open.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                createTask();
            }
        });

        LoadFormDataView loadFormDataView = findViewById(R.id.activity_test_create_form_load);

        Task task = new Task();
        task.setId("测试id");
        task.setExecutor("曹赤军");
        task.setCreateUser("chijun");
        task.setAnalysis("12345");
        task.setName("测试流程");
        task.setIllustrate("https://cjs-student.oss-cn-beijing.aliyuncs.com/20240506111405355,");
        loadFormDataView.setMTitleName("新建表单");

        loadFormDataView.setObject(task, Task.class, new FormDataFormatter() {
            @Override
            public String result(String fileName, ShowDataFieldView showDataFieldView) {
                if ("executor".equals(fileName)) {
                    ToastUtils.showShort("获取显示文本" + fileName);
                    return fileName;
                }
                return FormDataFormatter.super.result(fileName, showDataFieldView);
            }

            @Override
            public void jump(String fileName, ShowDataFieldView showDataFieldView) {
                if ("executor".equals(fileName)) {
                    ToastUtils.showShort("跳转提示");
                }

                FormDataFormatter.super.jump(fileName, showDataFieldView);
            }
        });

    }

    @Override
    public int initContentView() {
        return R.layout.activity_test_create_form;
    }


    /**
     * 创建任务
     */
    private void createTask(){
        LoadingDialog loadingDialog = new LoadingDialog(this);
        loadingDialog.showLoading();
        CreateFormDialog<ExamLoadConfig> taskCreateFormDialog = new CreateFormDialog<>(this, new ExamLoadConfig(), ExamLoadConfig.class, new CreateFormDialog.CreateFormListener<ExamLoadConfig>() {
            @Override
            public void onResult(ExamLoadConfig task, CreateFormDialog<ExamLoadConfig> createFormDialog) {

            }

            @Override
            public void onError(ExamLoadConfig task, String error) {

            }
        }, new OptionFormatter() {
            //设置选项显示的文本
            @Override
            public String formatItem(String s, @NonNull Object o) {

                return null;
            }

            //选择的选项
            @Override
            public String result(String s, int i, @NonNull Object o) {
                LogUtils.d("result: " + o.toString());
                return null;
            }

            @Override
            public Object[] getOption(String s) {

                if (s.equals("source")) {
                    return new String[]{"日常任务","做题任务"};
                }

                if (s.equals("bankId")) {
                    return new String[]{"日常任务","做题任务"};
                }

                if (s.equals("ksPath")) {
                    return new String[]{"日常任务","做题任务"};
                }

                if (s.equals("joinPerson")) {
                    return new String[]{"日常任务","做题任务"};
                }

                return null;
            }

            @Override
            public void jump(String fileName, InPutData inPutData) {
                LogUtils.d("jump: 跳转" + fileName+ "--" + inPutData.getFieldConfig().getFieldName());
            }
        });
        taskCreateFormDialog.show();
    }



}